package com.hera.process.config.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hera.base.util.FiltroDTO;
import com.hera.process.config.dao.BusinessDayDao;
import com.hera.process.config.dao.BusinessHourDao;
import com.hera.process.config.dao.CalendarDao;
import com.hera.process.config.dao.HolidayDao;
import com.hera.process.config.domain.Calendar;
import com.hera.process.config.service.CalendarService;

@Service("calendarService")
public class CalendarServiceImpl implements CalendarService {
	
	
	static final Logger logger = Logger.getLogger(CalendarServiceImpl.class);

	@Autowired
	private CalendarDao calendarDao;
	
	@Autowired
	private BusinessHourDao businessHourDao;
	
	@Autowired
	private BusinessDayDao businessDayDao;
	
	@Autowired
	private HolidayDao holidayDao;
	
	/**
	 * 
	 */
	public CalendarServiceImpl() {
		
	}
	@Override
	public Calendar findById(Long id) {
		
		return calendarDao.findOne(id);
	}
	@Override
	public void update(Calendar entity) {
		
		calendarDao.save(entity);
	}
	@Override
	public void save(Calendar entity) {
		
		calendarDao.save(entity);
	}
	@Override
	public void delete(Calendar entity) {
		//1.- Eliminamos los "BusinessHour"
		businessHourDao.deleteByCalendar(entity.getIdCalendar());
		//2.- Eliminamos los "BusinessDay"
		businessDayDao.deleteByCalendar(entity.getIdCalendar());
		//3.- Eliminamos los "Holiday"
		holidayDao.deleteByCalendar(entity.getIdCalendar());
		//4.- Eliminamos el "Calendar"
		calendarDao.delete(entity);
	}
	@Override
	public List<Calendar> findAll() {
		
		return calendarDao.findAll();
	}
	@Override
	public List<Calendar> findAll(FiltroDTO filtroDTO) {
		
		return calendarDao.obtenerEntidadesPorFiltros(filtroDTO);
	}
	

	

}
